﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CarsModel;
using System.Data;
using Lib.Data;
using System.Data.SqlClient;
namespace CarsDal
{
    public class CarsTypeDal
    {
        public static string ConnectionString = "Data Source=47.93.36.227;Initial Catalog=SecondHandCars;User ID=Yang;Pwd=qaz@WSXedc";
        SqlConnection con = new SqlConnection(ConnectionString);
        /// <summary>
        /// 显示车子品牌
        /// </summary>
        /// <returns></returns>
        public List<CarsType> CarsTypeList()
        {
            string sql = "select * from CarsType";
            SqlCommand com = new SqlCommand(sql,con);
            SqlDataAdapter adapter = new SqlDataAdapter(com);
            DataTable dt = new DataTable();
            adapter.Fill(dt);
            adapter.Dispose();
            List<CarsType> list = DataTableToList.DataTableToLista<CarsType>(dt);
            return list;
        }

        ///// <summary>
        ///// 车子品牌采集
        ///// </summary>
        ///// <param name="carstype"></param>
        ///// <returns></returns>
        //public int CarsTypeADD(string TypeName,string SetName)
        //{
        //    string sql = "insert into CarsType(TypeName,SetName) values('" + TypeName + "',"+SetName+")";
        //    SqlCommand com = new SqlCommand(sql,con);
        //    con.Open();
        //    int i = com.ExecuteNonQuery();
        //    con.Close();
        //    return i;
        //}
        /// <summary>
        /// 车子信息采集
        /// </summary>
        /// <param name="TypeName">品牌/系列名称</param>
        /// <param name="SetName">品牌主键ID</param>
        /// <returns></returns>
        public int CarsTypeADD(string TypeName, int SetName)
        {
            string sql = "insert into CarsType(TypeName,SetName) values('" + TypeName + "'," + SetName + ")";
            SqlCommand com = new SqlCommand(sql,con);
            con.Open();
            int i = com.ExecuteNonQuery();
            con.Close();
            return i;
        }


    }
}
